<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('出差申请列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="title"/>
                            </li>

                            <li>
                                <label>申请人：</label>
                                <input type="text" name="applyUserName"/>
                            </li>
                            <!--<li class="select-time">
                                <label>申请时间：</label>
                                <input type="text" class="time-input" id="applyTime" placeholder="申请时间" name="applyTime"/>
                            </li>-->

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="hr:businessTrip:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="hr:businessTrip:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="hr:businessTrip:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="hr:businessTrip:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>

     <div class="container-div" id="hiddenDiv" hidden="hidden">
         <div class="row">
             <form class="form-horizontal m" id="form-toolRepeal">
                 <div class="btn-group-sm" id="toolRepeal" >
                     <div class="form-group">
                         <input name="instanceId" id="instanceId" class="form-control" type="hidden">
                         <label class="col-sm-3 control-label is-required">撤回理由：</label>
                         <div class="col-sm-8">
                             <input name="message" class="form-control" type="text" required>
                         </div>
                     </div>
                 </div>
             </form>
         </div>
     </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('hr:businessTrip:edit')}]];
        var removeFlag = [[${@permission.hasPermi('hr:businessTrip:remove')}]];
        var prefix = ctx + "hr/businessTrip";

        var Statusdatas = [[${@dict.getType('auditStatus')}]];
        var currentUser = [[${currentUser}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail/{id}",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "出差申请",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'title', 
                    title: '标题'
                },
                {
                    field: 'reason', 
                    title: '出差事由',
                    visible: false
                },
                {
                    field: 'days', 
                    title: '出差总时长'
                },
                {
                    field: 'partner', 
                    title: '同行人'
                },
                {
                    field: 'type',
                    title: '出差类型',
                    formatter:function (value, row, index) {
                        if(value == '0'){
                            return '省内';
                        }
                        return '省外';
                    }
                },
                {
                    field: 'instanceId',
                    title: '流程实例ID',
                    visible: false
                },
                {
                    field: 'deptId',
                    title: '部门ID',
                    visible: false
                },
                {
                    field: 'deptName', 
                    title: '部门名称',
                    visible: false
                },
                {
                    field: 'postId', 
                    title: '岗位ID',
                    visible: false
                },
                {
                    field: 'postName', 
                    title: '岗位名称',
                    visible: false
                },
                {
                    field: 'createId', 
                    title: '创建者ID',
                    visible: false
                },
                {
                    field: 'updateId', 
                    title: '更新者ID',
                    visible: false
                },
                {
                    field: 'applyUserNum',
                    title: '发起人工号',
                    visible: false
                },
                {
                    field: 'applyUser', 
                    title: '申请人账号',
                    visible: false
                },
                {
                    field: 'applyUserName',
                    title: '申请人'
                },
                {
                    field: 'applyTime',
                    title: '申请时间'
                },
                {
                    field: 'taskName',
                    title: '当前任务名称',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return '<span class="badge badge-primary">' + value? value : "-" + '</span>';
                    }
                },
                {
                    field: 'todoUserName',
                    title: '当前处理人'
                },
                {
                    field : 'auditStatus',
                    title : '审核状态',
                    align : 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(Statusdatas, value);
                    }
                },
                {
                    field: 'remark', 
                    title: '备注',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.instanceId) {
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-eye"></i> 表单数据</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                            if (row.delFlag == 0 && (row.auditStatus == 0 || row.auditStatus == 1)){
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="repeal(\'' + row.instanceId + '\')"><i class="fa fa-remove"></i>撤回</a>');
                            }
                        } else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApply(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-user"></i> 提交申请</a> ');
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function submitApply(id, createBy) {
            if (createBy !== currentUser.loginName) {
                $.modal.alertWarning("不允许非创建人提交申请！");
                return;
            }
            $.modal.confirm("确认要提交申请吗?", function() {
                var url = prefix + "/submitApply";
                var data = { "id": id };
                $.operate.submit(url, "post", "json", data);
            });
        }

        function editForm(id, createBy) {
            if (createBy !== currentUser.loginName) {
                $.modal.alertWarning("不允许非创建人编辑表单！");
                return;
            }
            $.operate.edit(id);
        }

        function removeForm(id, createBy) {
            if (createBy !== currentUser.loginName) {
                $.modal.alertWarning("不允许非创建人删除表单！");
                return;
            }
            $.operate.remove(id);
        }

        function repeal(instanceId){
            var url = prefix + "/repeal";
            $('#instanceId').val(instanceId);
            layer.open({
                type: 1,
                area: ['600px', '300px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "撤销申请",
                content: $('#hiddenDiv'),
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: false,
                yes: function(index) {
                    if ($.validate.form('form-toolRepeal')) {
                        $.operate.save(url, $('#form-toolRepeal').serialize());
                    }
                }
            });
        }

        /* 查看审批历史 */
        function showHistoryDialog(instanceId) {
            var url = ctx + 'process/general/historyList/' + instanceId;
            $.modal.open("查看审批历史", url);
        }

        function showProcessImgDialog(instanceId) {
            var url = ctx + 'process/general/processImg/' + instanceId;
            $.modal.open("查看流程图 (标红表示已结束或活动中的流程)", url);
        }
    </script>
</body>
</html>